package cn.itcast.store.web.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.itcast.store.domain.PageModel;
import cn.itcast.store.domain.Product;
import cn.itcast.store.service.ProductService;
import cn.itcast.store.service.serviceImp.ProductServiceImp;
import cn.itcast.store.web.base.BaseServlet;

/**
 * Servlet implementation class ProductServlet
 */
public class ProductServlet extends BaseServlet {
	
	
	public String findProductByPid(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException, SQLException {
		String pid = request.getParameter("pid");
		//System.out.println(pid);
		ProductService ProductService=new ProductServiceImp();
		
		Product pro=ProductService.findProductByPid(pid);
		//将商品放入request,
		System.out.println(pro);
		request.setAttribute("pro", pro);	
		return "/jsp/product_info.jsp";	
	}
	
	public String findProductsWithCidAndPage(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException, SQLException {
		
		
		String cid = request.getParameter("cid");
		int num =Integer.parseInt(request.getParameter("num"));
		ProductService  ProductService=new ProductServiceImp();
		PageModel pm=ProductService.findProductsWithCidAndPage(cid,num);
		System.out.println(pm);
		request.setAttribute("page", pm);
		//转发到"/jsp/product_list.jsp"
		return "/jsp/product_list.jsp";
	}
	
	
	
}
